//
//  YYImageCryptoManager.m
//  Pthread
//
//  Created by Yanyan Jiang on 2025/3/7.
//  Copyright © 2025 Yanyan Jiang. All rights reserved.
//

#import "YYImageCryptoManager.h"
#import "NSData+Encryption.h"


@implementation YYImageCryptoManager

+ (NSData *)encryptImage:(UIImage *)image key:(NSData *)key iv:(NSData *)iv {
    // 将 UIImage 转换为 NSData（PNG 格式）
    NSData *imageData = UIImagePNGRepresentation(image);
    if (!imageData) {
        return nil;
    }
    
    // 使用 AES-256-CBC 加密
    return [imageData aes256EncryptWithKey:key iv:iv];
}

+ (UIImage *)decryptImageData:(NSData *)encryptedData key:(NSData *)key iv:(NSData *)iv {
    // 使用 AES-256-CBC 解密
    NSData *decryptedData = [encryptedData aes256DecryptWithKey:key iv:iv];
    if (!decryptedData) {
        return nil;
    }
    
    // 将 NSData 转换为 UIImage
    return [UIImage imageWithData:decryptedData];
}


@end
